import { createRouter, createWebHashHistory } from 'vue-router'
import { useUserStore } from '@/stores/modules/userStore'
// import { Dialog } from 'vant';
// import { showConfirmDialog } from 'vant';

/** 动态路由信息 */
export const asyncRoute = [
  {
    path: '/newSuddenly',
    name: 'newSuddenly',
    component: () => import("@/views/suddenlyStop/newSuddenly/index.vue"),
    meta: {
      title: '新建突发停水',
    }
  },

  {
    path: '/publicityList',
    name: 'publicityList',
    component: () => import("@/views/planStop/publicityList/index.vue"),
    meta: {
      title: '停水公示',
    }
  },
  {
    path: '/stopList',
    name: 'suddenlyStopList',
    component: () => import("@/views/suddenlyStop/stopList/index.vue"),
    meta: {
      title: '突发停水列表',
    }
  },
  {
    path: '/planFormulation',
    name: 'planFormulation',
    component: () => import("@/views/planStop/planFormulation/index.vue"),
    meta: {
      title: '方案制定',
    }
  },
  {
    path: '/planIntegration',
    name: 'planIntegration',
    component: () => import("@/views/planStop/planIntegration/index.vue"),
    meta: {
      title: '方案整合',
    }
  },
  {
    path: '/schemeReview',
    name: 'schemeReview',
    component: () => import("@/views/planStop/schemeReview/index.vue"),
    meta: {
      title: '方案审核',
    }
  },
  {
    path: '/outageProject',
    name: 'outageProject',
    component: () => import("@/views/outageProject/index.vue"),
    meta: {
      title: '停水工程',
    }
  },

  {
    path: '/protectWater',
    name: 'protectWater',
    component: () => import("@/views/protectWater/index.vue"),
    meta: {
      title: '保水设置',
    }
  },
  {
    path: '/protectWater',
    name: 'protectWater',
    component: () => import("@/views/protectWater/index.vue"),
    meta: {
      title: '保水设置',
    }
  },
  
]




/**
 * title   页面名字
 * tabbar  是否是bar页签
 * isNeedLogin  页面进入是否需要完善信息（需要就跳转到完善页面）
 */

const routes = [
  {
    path: '/',
    name: 'home',
    component: () => import("@/views/home/index.vue"),
    meta: {
      title: '首页'
    }
  },

  {
    path: '/mine',
    name: 'mine',
    component: () => import("@/views/mine/index.vue"),
    meta: {
      title: '个人中心'
    }
  },

  {
    path: '/scanLogin',
    name: 'scanLogin',
    component: () => import("@/views/scanLogin/index.vue"),
    meta: {
      title: '扫码登录'
    }
  },


  {
    path: "/404",
    name: "404",
    component: () => import("@/views/error/404.vue"),
    meta: {
      title: "404"
    }
  },
  {
    path: '/mine/stopList',
    name: 'mineSuddenlyStopList',
    component: () => import("@/views/suddenlyStop/mine/index.vue"),
    meta: {
      title: '我的突发停水',
    }
  },
  // ...asyncRoute
  // {
  //   path: '/newPlan',
  //   name: 'newPlan',
  //   component: () => import("@/views/planStop/newPlan/index.vue"),
  //   meta: {
  //     title: '新建计划停水',
  //   }
  // },



]

const router = createRouter({
  // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
  history: createWebHashHistory(),
  routes, // `routes: routes` 的缩写
})

// /** 选择完善信息 */
// const perfectInfoJudgment = async () => {
//   return new Promise((resolve, reject) => {
//     showConfirmDialog({
//       title: '提示',
//       message:
//         '请完善信息，查看更多详情',
//       confirmButtonText: '立即完善'
//     })
//       .then(() => {
//         resolve({ name: 'perfectInfo' })
//       })
//       .catch(() => {
//         resolve({ name: 'home' })
//       });
//   })
// }

// 处理需要完善信息的页面
router.beforeEach(async (to, from) => {
  // if (to.matched.length === 0) {
  //   next('/404')

  // } else {
  //   next()
  // }

  // if (to.meta && to.meta.isNeedLogin && !useUserStore().isLogin) {
  //   const backInfo: any = await useUserStore().perfectInfoJudgment()
  //   return backInfo
  // }
})

router.afterEach((to, from) => {
  document.title = (to.meta.title || '标题') as string
})

export default router